package com.ruoyi.webInfor.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.webInfor.domain.DownInformation;
import com.ruoyi.webInfor.service.IDownInformationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 下载中心Controller
 * 
 * @author ruoyi
 * @date 2021-12-20
 */
@RestController
@RequestMapping("/web/downInfor")
public class DownInformationController extends BaseController
{
    @Autowired
    private IDownInformationService downInformationService;

    /**
     * 查询下载中心列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DownInformation downInformation)
    {
        startPage();
        List<DownInformation> list = downInformationService.selectDownInformationList(downInformation);
        return getDataTable(list);
    }

    /**
     * 导出下载中心列表
     */
    @Log(title = "下载中心", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DownInformation downInformation)
    {
        List<DownInformation> list = downInformationService.selectDownInformationList(downInformation);
        ExcelUtil<DownInformation> util = new ExcelUtil<DownInformation>(DownInformation.class);
        util.exportExcel(response, list, "下载中心数据");
    }

    /**
     * 获取下载中心详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(downInformationService.selectDownInformationById(id));
    }

    /**
     * 新增下载中心
     */
    @Log(title = "下载中心", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DownInformation downInformation)
    {
        downInformation.setId(IdUtils.fastSimpleUUID());
        return toAjax(downInformationService.insertDownInformation(downInformation));
    }

    /**
     * 修改下载中心
     */
    @Log(title = "下载中心", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DownInformation downInformation)
    {
        return toAjax(downInformationService.updateDownInformation(downInformation));
    }

    /**
     * 删除下载中心
     */
    @Log(title = "下载中心", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(downInformationService.deleteDownInformationByIds(ids));
    }
}
